1606B - Update Files - CodeForces Solution


greedy implementation math *1100

Please click on ads to support us..

Python Code:


class Solution:
    def fileTransfer(self, n : int, k:int) -> None:
        ans = 0
        curr = 1
        while curr < k:
            curr *=2
            ans+=1
        
        if (curr < n):
            ans += (n - curr + k - 1) // k;
            
        print(ans)
 
obj = Solution()
t = int(input())
for _ in range(t):
    n,  k = list(map(int, input().split()))
    obj.fileTransfer(n, k)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t ; cin >>t ;
    long long n, k ; 
    while(t--){
        cin >> n >> k ; 
        long long good = 1 ; 
        long long i = 0  ;
        while(good<k){
            i++ ; 
            good *= 2 ; 
        }
        if(good>=n) cout << i <<endl ;
        else{
            cout << (((n-good)+k-1)/k)+i <<endl;
        }
    }

}


Comments

Submit
0 Comments
More Questions

1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game